//
//  LearnCenterTableViewCell.m
//  LiuHeBao
//
//  Created by zr on 2018/8/22.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "LearnCenterTableViewCell.h"

@interface LearnCenterTableViewCell ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UIImageView * leftImageView;
@property (nonatomic, weak)UILabel * readLabel;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation LearnCenterTableViewCell


- (void)setModel:(LearningModel *)model{
    
    _model = model;
    
    NSURL * url = [NSURL URLWithString:model.images];
    [self.leftImageView sd_setImageWithURL:url];
    
    self.titleLabel.text = model.title;
    
    self.readLabel.text = [NSString stringWithFormat:@"%@次阅读",model.read];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}



- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor whiteColor];
    
    
    UIImageView * leftImageView = [UIImageView new];
    
    leftImageView.backgroundColor = [UIColor lightGrayColor];
    
    self.leftImageView = leftImageView;
    
    [self.contentView addSubview:self.leftImageView];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    titleLabel.numberOfLines = 2;
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    
    UILabel * readLabel = [UILabel new];
    
    readLabel.textColor = ColorWithRGB(0xB3B3B3);
    readLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    readLabel.text = @"1253阅读";
    
    self.readLabel = readLabel;
    
    [self.contentView addSubview:self.readLabel];
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);//[UIColor lightGrayColor];
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
}


- (void)layoutSubviews{
    
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(12.5 * SCREENH6);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(125 * SCREENH6);
        make.height.mas_equalTo(70 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.leftImageView);
        make.leading.mas_equalTo(self.leftImageView.mas_trailing).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
    }];
    
    [self.readLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.leftImageView);
        make.leading.mas_equalTo(self.titleLabel);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}




- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
